package kisti.lod.sindice.query;

/**
 * Extension of the Sindice TermFilterQuery Class to allow the use of the filter
 * functionality of Sindice API V3
 * @author Sebastian
 *
 */
public class TermFilterQuery extends MySearchQuery {

    private boolean sortByDate; 

    public static String SINDICE_ENDPOINT_PATTERN =SINDICE_ENDPOINT_PREFIX + "/v3/search?q=%s&qt=term&page=%s";

	private String term;
	private String[] filters;

	public TermFilterQuery(String term, boolean sortByDate, String[] filters) {
		super();
		if(term == null) {
            throw new IllegalArgumentException("Search term cannot be null");
        }
		this.filters = filters;
		this.term = term;
		this.sortByDate = sortByDate;
	}

	@Override
	protected String formURL(int page) {
        String url = String.format(
                SINDICE_ENDPOINT_PATTERN,
                encode(term),
                page
        );
        for(String filter : filters) {
        	url += "&fq=" + encode(filter);
        }
        return url;
	}
}